﻿using System;
using System.Collections.Generic;
using System.Text;
using StackExchange.Redis;

namespace IotS.Core.Helpers
{
    public class RedisHelper
    {
        private static readonly IDatabase Db;

        static RedisHelper()
        {
            var redis = ConnectionMultiplexer.Connect(ConfigHelper.Settings.Redis.Host);
            Db = redis.GetDatabase(2);
        }

        public static string Get(string key)
        {
            if (!Db.KeyExists(key))
                return null;
            return Db.StringGet(key).ToString() ?? "";
        }

        public static void Set(string key, string value, TimeSpan? expire = null)
        {
            Db.StringSet(key, value, expire);
        }
    }
}
